package com.ruoyi.web.controller.emergency;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.common.helper.LoginHelper;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.EmgWarehouseVo;
import com.ruoyi.system.domain.bo.EmgWarehouseBo;
import com.ruoyi.system.service.IEmgWarehouseService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资仓库
 *
 * @author ruoyi
 * @date 2023-11-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/emg/warehouse")
public class EmgWarehouseController extends BaseController {

    private final IEmgWarehouseService iEmgWarehouseService;

    /**
     * 查询物资仓库列表
     */
    //@SaCheckPermission("emergency:warehouse:list")
    @GetMapping("/list")
    public TableDataInfo<EmgWarehouseVo> list(EmgWarehouseBo bo, PageQuery pageQuery) {
        return iEmgWarehouseService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出物资仓库列表
     */
    //@SaCheckPermission("emergency:warehouse:export")
    @Log(title = "物资仓库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EmgWarehouseBo bo, HttpServletResponse response) {
        List<EmgWarehouseVo> list = iEmgWarehouseService.queryList(bo);
        ExcelUtil.exportExcel(list, "物资仓库", EmgWarehouseVo.class, response);
    }

    /**
     * 获取物资仓库详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("emergency:warehouse:query")
    @GetMapping("/{id}")
    public R<EmgWarehouseVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iEmgWarehouseService.queryById(id));
    }

    /**
     * 新增物资仓库
     */
    //@SaCheckPermission("emergency:warehouse:add")
    @Log(title = "物资仓库", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EmgWarehouseBo bo) {
        bo.setDeptId(LoginHelper.getDeptId());
        return toAjax(iEmgWarehouseService.insertByBo(bo));
    }

    /**
     * 修改物资仓库
     */
    //@SaCheckPermission("emergency:warehouse:edit")
    @Log(title = "物资仓库", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EmgWarehouseBo bo) {
        return toAjax(iEmgWarehouseService.updateByBo(bo));
    }

    /**
     * 删除物资仓库
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("emergency:warehouse:remove")
    @Log(title = "物资仓库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iEmgWarehouseService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
